<%@ page contentType="text/html; charset=UTF-8"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%String baseUrl = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath() + "/"; %>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml" >
<head>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery-1.9.1-vsdoc.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery-1.9.1.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery.messager.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/bootstrap.min.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery.qrcode.min.js"></script>
<link type="text/css" rel="stylesheet" href="<%=request.getContextPath()%>/res/css/login.css">
<link type="text/css" rel="stylesheet" href="<%=request.getContextPath()%>/res/css/style.css">
<link type="text/css" rel="stylesheet" href="<%=request.getContextPath()%>/res/css/index.css">
<jsp:include page="../admin_head.jsp">
	<jsp:param value="用户界面" name="title" />
</jsp:include>

</head>
<body>
	<div class="container-fluid">
		<div class="row">
			<div class="col-md-2"></div>
			<div class="col-md-8">
				<div class="panel panel-success" align="center">
				<div class="panel-heading">
				<h1 >课堂教学质量评价系统</h1><br/>当前用户:${user.nickName }&nbsp;&nbsp;&nbsp;
						当前用户角色：${user.userRole }
				&nbsp;&nbsp;&nbsp;&nbsp;<a href="userlist.action?userId=${user.id }"><button class="btn btn-sm btn-success">首页</button></a>
						<a href="${pageContext.request.contextPath }/user/user.action"> <button class="btn btn-sm btn-danger" > <B> 退出登录 </B> </button> </a></div>
				</div>
				
				<!-- 功能按钮start -->
				<div id="btns_div" style="width:300px;" >
					<div class="panel-body">
						<button class="btn btn-info" data-toggle="modal" data-target="#modPwdModal" style="width: 160px" id="mod_pwd"> <B> 修改密码 </B> </button>
					</div><br/>
					<div class="panel-body">
						<a href="${pageContext.request.contextPath }/user/edit.action?id=${user.id }">
						<button class="btn btn-info" style="width: 160px"> <B> 个人信息查询 </B> </button>
						</a>
					</div><br/>
					<c:if test="${user.userType == 2 or user.userType ==3 }">
					<div class="panel-body">
						<a href="${pageContext.request.contextPath }/user/addEvaItemsPage.action?operatorId=${user.id }">
						<button class="btn btn-info" style="width: 160px"> <B> 维护课堂评价标准</B> </button>
						</a>
					</div> <br/>
					</c:if>
					<c:if test="${user.userType ne 3 }">
					<div class="panel-body">
						<a href="${pageContext.request.contextPath }/user/stu_class_info.action?id=${user.id }">
						<button class="btn btn-info" style="width: 160px"> <B> 课程信息查询 </B> </button>
						</a>
					</div><br/>
					</c:if>
					<c:if test="${user.userType eq 3 }"> 
						<div class="panel-body">
						<a href="${pageContext.request.contextPath }/user/allUserlist.action?id=${user.id }&userType=1">
						<button class="btn btn-info" style="width: 160px"> <B> 用户列表 </B> </button>
						</a>
					</div> <br/>
					<div class="panel-body">
						<a href="${pageContext.request.contextPath }/user/getAllClassInfo.action?operatorId=${user.id }">
						<button class="btn btn-info" style="width: 160px"> <B> 评价信息查询 </B> </button>
						</a>
					</div> <br/>
					<div class="panel-body">
						<a href="${pageContext.request.contextPath }/user/addClassInfoPage.action?operatorId=${user.id }">
						<button class="btn btn-info" style="width: 160px"> <B> 添加课程信息 </B> </button>
						</a>
					</div> <br/>
					<div class="panel-body">
						<a href="${pageContext.request.contextPath }/user/addClassAndUserPage.action?operatorId=${user.id }">
						<button class="btn btn-info" style="width: 160px"> <B> 添加课程对应用户 </B> </button>
						</a>
					</div> <br/>
					<div class="panel-body">
						<button class="btn btn-info" style="width: 160px" data-toggle="modal"   data-target="#uploadClassModal" id="upload_class"><B>上传课程信息 </B></button>
					</div> <br/>
					<div class="panel-body">
						<button class="btn btn-info" style="width: 160px" data-toggle="modal"   data-target="#uploadUserModal" id="upload_user"><B>上传用户信息 </B></button>
					</div> <br/>
					</c:if>
					<div class="panel-body">
						<c:if test="${user.userType eq 1 }">
						<a href="${pageContext.request.contextPath }/user/stu_class_evaluation_info.action?id=${user.id }">
						<button class="btn btn-info" style="width: 160px"> <B> 评价信息查询 </B> </button>
						</a>
						</c:if>
						<c:if test="${user.userType eq 2 }">
						<%-- <a href="${pageContext.request.contextPath }/user/tea_evaluation_info.action?id=${user.id }"> --%>
						<a href="${pageContext.request.contextPath }/user/getAllClassInfo.action?operatorId=${user.id }">
						<button class="btn btn-info" style="width: 160px"> <B> 评价信息查询 </B> </button>
						</a>
						</c:if>
					</div><br/>
					<c:if test="${user.userType eq 2 }">
					<div class="panel-body">
						<button class="btn btn-info" style="width: 160px" onclick="showQrCode()"> <B> 获取课堂评价二维码 </B> </button><br />
					</div><br/>
					</c:if>
				</div>
				<!-- 功能按钮end -->
				
				<!-- 选择课堂以获取二维码 start -->
	<div class="panel-body" style="margin-top:-500px;margin-left: 300px;width:900px">
	<div style="display:none" class="panel panel-primary" align="center"  id="qr_window" >
					<div class="panel-heading"> <h3 class="panel-title">获取课堂二维码</h3>
						<B><font class="panel-title" color="red" size="4">注意：这里如果是用本机的tomcat启动，手机扫码后是没有办法直接访问该网址的。
						<br/>可以将localhost:8080的地址通过映射工具映射到外网，这样手机就可以扫码访问了。（映射工具例如：natapp）</font> </B>					</div>
					<div class="panel-body">
								<div class="input-group" style="width: 200px;" id="class_div">
									<span class="input-group-addon">课程</span> 
									<select class="form-control" name="departmentId" id="classSelect">
										<c:if test="${classList ne null}">
											<c:forEach items="${classList}" var="cl" varStatus="vs">
												<option value="${cl.id}" >${cl.name}</option>
											</c:forEach>
										</c:if>
									</select>
								</div>
								<div class="input-group" style="width: 200px;" id="class_div">
									<span class="input-group-addon">第几次课程</span> 
									<input class="form-control" id="class_count" type="number" value="0"></input>
								</div>
								<div style="margin-top:50px;" class="qrcodediv" ></div>
								<br/><br/>
						<button id="qrc_btn" class="btn btn-success" onClick="getQrCode()">获取</button>&nbsp;&nbsp;&nbsp;&nbsp;
						<button id="qrcback_btn" class="btn btn-default" onClick="back()">返回</button>
					</div>
	</div>
	</div>
	<!-- 选择课堂以获取二维码end  -->
			</div>
			<div class="col-md-2"></div>
		</div>
	</div>
<!-- 导入课程start  -->
		<div class="modal fade" id="uploadClassModal" tabindex="-1" user="dialog" aria-labelledby="mod_modal_label" aria-hidden="true">
								<div class="modal-dialog">
									<div class="modal-content">
										<div class="modal-header">
											<button type="button" class="close" data-dismiss="modal" aria-label="Close">
												<span aria-hidden="true">&times;</span>
											</button>
											<h4 class="modal-title" id="mod_modal_label">导入课程</h4>
										</div>
										<input type="hidden" id="type" value="">
										<form id="uploadForm" user="form" method="post" action="uploadClassReview.action?operatorId=${user.id }" autocomplete="off" class="form-horizontal" enctype="multipart/form-data" onsubmit="return importSubmit()">
											<div class="modal-body">
												<div class="form-group">
													<label class="col-sm-3 control-label no-padding-right"
														for="mod_user_real_name">导入文件：</label>
													<div class="col-sm-9">
													&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
														<input type="file" name="uploadFile" id="uploadFile" class="hidden">
														<input type="text"  id="uploadFileName" name="uploadFileName" placeholder="请选择导入的文件" check-type="required" value="" readonly="true" size="20">
														<a href="javascript:;" class="btn btn-sm btn-success" onclick="$('input[id=uploadFile]').click();">点此选择</a>
													</div>
												</div>
												<div class="form-group">
													<label class="col-sm-3 control-label no-padding-right"
														for="mod_user_pwd_cfn"> </label>
													<div class="col-sm-9">
													   支持Excel文件:xls,xlsx。最多可支持500条<br>
													</div>
												</div>
												<div class="form-group">
													<label class="col-sm-3 control-label no-padding-right" for="mod_user_pwd_cfn"> </label>
													<div class="col-sm-9">
													&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
														 <a href="<%=request.getContextPath() %>/user/download.action?path=uploads/upload_model_class.xlsx" class="btn btn-sm btn-info">示例文件</a>
													</div>
												</div>
											</div>
											 <div class="modal-footer">
												<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                                          		<button type="submit" class="btn btn-success" id="commitButton">导入</button>
											</div>
										</form>
									</div>
								</div>
							</div>
<!-- 导入课程end  -->
<!-- 导入用户start  -->
		<div class="modal fade" id="uploadUserModal" tabindex="-1" user="dialog" aria-labelledby="mod_modal_label" aria-hidden="true">
								<div class="modal-dialog">
									<div class="modal-content">
										<div class="modal-header">
											<button type="button" class="close" data-dismiss="modal" aria-label="Close">
												<span aria-hidden="true">&times;</span>
											</button>
											<h4 class="modal-title" id="mod_modal_label">导入用户</h4>
										</div>
										<input type="hidden" id="type" value="">
										<form user="form" method="post" action="uploadUserReview.action?operatorId=${user.id }" autocomplete="off" class="form-horizontal" enctype="multipart/form-data" onsubmit="return importUserSubmit()">
											<div class="modal-body">
												<div class="form-group">
													<label class="col-sm-3 control-label no-padding-right"
														for="mod_user_real_name">导入文件：</label>
													<div class="col-sm-9">
													&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
														<input type="file" name="uploadUserFile" id="uploadUserFile" class="hidden">
														<input type="text"  id="uploadUserFileName" name="uploadUserFileName" placeholder="请选择导入的文件" check-type="required" value="" readonly="true" size="20">
														<a href="javascript:;" class="btn btn-sm btn-success" onclick="$('input[id=uploadUserFile]').click();">点此选择</a>
													</div>
												</div>
												<div class="form-group">
													<label class="col-sm-3 control-label no-padding-right"
														for="mod_user_pwd_cfn"> </label>
													<div class="col-sm-9">
													   支持Excel文件:xls,xlsx。最多可支持500条<br>
													</div>
												</div>
												<div class="form-group">
													<label class="col-sm-3 control-label no-padding-right"
														for="mod_user_pwd_cfn"> </label>
													<div class="col-sm-9">
													&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
														 <a href="<%=request.getContextPath() %>/user/download.action?path=uploads/upload_model_user.xlsx" class="btn btn-sm btn-info">示例文件</a>
													</div>
												</div>
											</div>
											 <div class="modal-footer">
												<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                                          		<button type="submit" class="btn btn-success" id="commitUserButton">导入</button>
											</div>
										</form>
									</div>
								</div>
							</div>
<!-- 导入用户end  -->

<!--修改密码弹框start -->
<div class="modal fade" id="modPwdModal" tabindex="-1" user="dialog" aria-labelledby="mod_modal_label" aria-hidden="true">
								<div class="modal-dialog">
									<div class="modal-content">
										<div class="modal-header">
											<button type="button" class="close" data-dismiss="modal" aria-label="Close">
												<span aria-hidden="true">&times;</span>
											</button>
											<h4 class="modal-title" id="mod_modal_label">修改密码</h4>
										</div>
										<form id="pwdForm" user="form" method="post" action="" autocomplete="off" class="form-horizontal" enctype="multipart/form-data">
											<div class="modal-body">
												<div class="form-group">
													<label class="col-sm-3 ">旧密码：</label>
													<input type="password" class="col-sm-4" id="oldPwd" check-type="required">
												</div>
												<div class="form-group">
													<label class="col-sm-3 ">新密码：</label>
													<input type="password" class="col-sm-4"  id="newPwd1" check-type="required">
												</div>
												<div class="form-group">
													<label class="col-sm-3 ">确认密码：</label>
													<input type="password" class="col-sm-4" id="newPwd2" check-type="required">
												</div>
											</div>
											<button type="submit" class="btn btn-success" id="sub" style="display:none"></button>
										</form>
										 <div class="modal-footer">
                                          		<button class="btn btn-success" onclick="modPwd()">提交</button>
												<button type="button" class="btn btn-default" data-dismiss="modal">返回</button>
										</div>
									</div>
								</div>
							</div>
<!--修改密码弹框end -->
<script>
		$(document).ready(function(){
			$('input[id=uploadFile]').change(function() {  
		    	var file=$(this).val();
				if(''==file){
					$('#uploadFileName').val("");
					alert("错误提示:请选择你要导入的文件");
					$("#commitButton").removeClass();
					$("#commitButton").addClass("btn btn-default");
					$('#commitButton').attr('disabled',true);
				}else{
					var index = file.lastIndexOf(".");
					if(index < 0) {
						$('#uploadFileName').val("");
						alert("错误提示:文件格式不正确");
						$("#commitButton").removeClass();
						$("#commitButton").addClass("btn btn-default");
						$('#commitButton').attr('disabled',true);
					}else {
						var ext = file.substring(index + 1, file.length);
						if(ext != "xls" && ext != "xlsx") {
						   alert("错误提示:文件格式不正确");
						   $('#uploadFileName').val("");
							$("#commitButton").removeClass();
							$("#commitButton").addClass("btn btn-default");
						   $('#commitButton').attr('disabled',true);
						}else{
							$('#commitButton').attr('disabled',false);
							$("#commitButton").removeClass();
							$("#commitButton").addClass("btn btn-primary");
							var fileName = file.substring(file.lastIndexOf("\\") + 1);
							$('#uploadFileName').val(fileName);
						}
					}
				}
			}); 
			
			$('input[id=uploadUserFile]').change(function() {  
		    	var file=$(this).val();
				if(''==file){
					$('#uploadUserFileName').val("");
					alert("错误提示:请选择你要导入的文件");
					$("#commitUserButton").removeClass();
					$("#commitUserButton").addClass("btn btn-default");
					$('#commitUserButton').attr('disabled',true);
				}else{
					var index = file.lastIndexOf(".");
					if(index < 0) {
						$('#uploadFileName').val("");
						alert("错误提示:文件格式不正确");
						$("#commitUserButton").removeClass();
						$("#commitUserButton").addClass("btn btn-default");
						$('#commitUserButton').attr('disabled',true);
					}else {
						var ext = file.substring(index + 1, file.length);
						if(ext != "xls" && ext != "xlsx") {
						   alert("错误提示:文件格式不正确");
						   $('#uploadFileName').val("");
							$("#commitUserButton").removeClass();
							$("#commitUserButton").addClass("btn btn-default");
						   $('#commitUserButton').attr('disabled',true);
						}else{
							$('#commitUserButton').attr('disabled',false);
							$("#commitUserButton").removeClass();
							$("#commitUserButton").addClass("btn btn-primary");
							var fileName = file.substring(file.lastIndexOf("\\") + 1);
							$('#uploadUserFileName').val(fileName);
						}
					}
				}
			}); 
		});
		
		function importSubmit() {
			var fileName=$("#uploadFileName").val();
			if('' == fileName || null == fileName){
				alert("错误提示:请选择你导入的文件");
				return false;
			}
			$("#commitButton").text("处理中..").attr("disabled", true);
			return true;
		}
		
		function importUsesrSubmit() {
			var fileName=$("#uploadFileName").val();
			if('' == fileName || null == fileName){
				alert("错误提示:请选择你导入的文件");
				return false;
			}
			$("#commitUserButton").text("处理中..").attr("disabled", true);
			return true;
		}
</script>
<script type="text/javascript">
	var baseUrl = "<%= baseUrl%>";
	window.onload = function(){
		var btn = "${btn}";
		if(btn == "mod_pwd"){
			document.getElementById("mod_pwd").click();
		}else if(btn == "upload_user"){
			document.getElementById("upload_user").click();
		}else if(btn == "upload_class"){
			document.getElementById("upload_class").click();
		}else if(btn == "QR"){
			showQrCode();
		}
	}
	//控制显示（1显示 2隐藏）
	function show(id,type){
		if(type == 1){
			document.getElementById(id).removeAttribute("style");
		}else{
			document.getElementById(id).style.display = "none";
		}
	}
	
	function showQrCode(){
		show("qr_window",1);
	}
	function back(){
		location.href = baseUrl+"/user/userlist.action?userId=${user.id}"
		show("qr_window",2);
		show("btns_div",1);
	}
	
	function getQrCode(){
		var classId = $('#classSelect option:selected') .val();
		var classCount = $("#class_count").val();
		if(classCount == null || classCount == "" || classCount == 0){
			alert("请输入第几次课程数(正整数)！");
			return;
		}
		var curUrl = location.href.replace("userlist.action","loginByPhone.action") + "&classId=" + classId +"&class_count=" + classCount;
		content = curUrl;
		//content="http://www.baidu.com"
		$(function(){
			$(".qrcodediv").qrcode({
				text : content
			})
		});
	}
	
	//提交修改密码
	function modPwd(){
		var oldPwd = $("#oldPwd").val();
		var newPwd1 = $("#newPwd1").val();
		var newPwd2 = $("#newPwd2").val();
		var password = "${user.password}";
		if(oldPwd == password){
			if(newPwd1 == newPwd2){
				document.getElementById("pwdForm").action="modPwd.action?operatorId=${user.id }&password="+newPwd1;
				document.getElementById("sub").click();
			}else{
				alert("新密码两次输入结果不一致，请重试！");
			}
		}else{
			alert("旧密码输入错误，请重试！");
		}
	}
</script>

</body>
</html>